/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jpThongKePNTheoThang.java
 *
 * Created on Jan 10, 2012, 6:57:03 PM
 */
package GUI;

/**
 *
 * @author Admin
 */
import Bussiness.PhieuNhap;
import Bussiness.PhieuXuat;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import DatabaseAccess.DBHelper;
//import DatabaseAccess.ReportProcessDatabase;
import DatabaseAccess.DBHelper01;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
public class jpThongKePNTheoThang extends javax.swing.JPanel {
    static String bot;
    private DefaultTableModel modelTable = new DefaultTableModel();
    /** Creates new form jpThongKePNTheoThang */
    public jpThongKePNTheoThang() throws SQLException {
         bot = "";
        initComponents();
        Vector v = new Vector();
        PhieuNhap b = new PhieuNhap();
        v = b.getAllPhieuNhap();
        this.loadTable(v);
    }
    public void loadTable(Vector v) {
        modelTable.setNumRows(0);
        Vector v1 = new Vector();
        v1.addElement("Mã Hàng");
        v1.addElement("Số Phiếu Nhập");
        v1.addElement("Số Lượng Yêu Cầu");
        v1.addElement("Số Lượng Thực");
        v1.addElement("Ngày Nhập");
        modelTable.setColumnIdentifiers(v1);
        PhieuNhap b = new PhieuNhap();
        for (int i = 0; i < v.size(); i++) {
            b = (PhieuNhap) v.get(i);
            Vector row = new Vector();
            row.addElement(b.getMaHang());
            row.addElement(b.getSoPhieuNhap());
            row.addElement(b.getSoLuongYeuCau());
            row.addElement(b.getSoLuongThuc());
            row.addElement(b.getNgayNhap());
            modelTable.addRow(row);
        }
        tblPhieuNhap.setModel(modelTable);
        int r = tblPhieuNhap.getSelectedRow();
    }
    public void searchThang1() {
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() ==1) {
                v = b.getPhieuNhapThang1();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }
    public void searchThang2() {
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() == 2) {
                v = b.getPhieuNhapThang2();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }
    public void searchThang3() {
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() == 3) {
                v = b.getPhieuNhapThang3();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }
    public void searchThang4() {
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() == 4) {
                v = b.getPhieuNhapThang4();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }
    public void searchThang5() {
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() == 5) {
                v = b.getPhieuNhapThang5();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }
    public void searchThang6() {
        
        
        
        
        
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() == 6) {
                v = b.getPhieuNhapThang6();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }
    public void searchThang7() {
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() == 7) {
                v = b.getPhieuNhapThang7();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }
    public void searchThang8() {
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() == 8) {
                v = b.getPhieuNhapThang8();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }
    public void searchThang9() {
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() == 9) {
                v = b.getPhieuNhapThang9();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }
    public void searchThang10() {
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() == 10) {
                v = b.getPhieuNhapThang10();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }
    public void searchThang11() {
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() == 11) {
                v = b.getPhieuNhapThang11();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }
    public void searchThang12() {
        PhieuNhap b = new PhieuNhap();
        Vector v = new Vector();
        try {
            if (cboThang.getSelectedIndex() == 12) {
                v = b.getPhieuNhapThang12();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        this.loadTable(v);
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cboThang = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblPhieuNhap = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        btnThongKe = new javax.swing.JButton();

        cboThang.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));

        jLabel5.setText("Tháng");

        tblPhieuNhap.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tblPhieuNhap);

        jButton3.setText("In Báo Cáo");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel1.setText("Thống Kê Phiếu Nhập Theo Tháng");

        btnThongKe.setText("Thống kê");
        btnThongKe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThongKeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 631, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(btnThongKe)
                .addGap(34, 34, 34)
                .addComponent(jLabel5)
                .addGap(39, 39, 39)
                .addComponent(cboThang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 217, Short.MAX_VALUE)
                .addComponent(jButton3)
                .addGap(94, 94, 94))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(169, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(165, 165, 165))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(37, 37, 37)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cboThang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jButton3)
                    .addComponent(btnThongKe))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(60, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

            // TODO add your handling code here:
        Connection con = new DBHelper01().DBHelper01();
        Map<String,Object> param = new HashMap<String,Object>();
        if(cboThang.getSelectedIndex()==1){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongKePNTheoThang1.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongKePNTheoThang1.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
        if(cboThang.getSelectedIndex()==2){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongKePNTheoThang2.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongKePNTheoThang2.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
        if(cboThang.getSelectedIndex()==3){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongKePNTheoThang3.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongKePNTheoThang3.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
        if(cboThang.getSelectedIndex()==4){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongKePNTheoThang4.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongKePNTheoThang4.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
        if(cboThang.getSelectedIndex()==5){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongKePNTheoThang5.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongKePNTheoThang5.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
        if(cboThang.getSelectedIndex()==6){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongKePNTheoThang6.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongKePNTheoThang6.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
        if(cboThang.getSelectedIndex()==7){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongKePNTheoThang7.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongKePNTheoThang7.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
        if(cboThang.getSelectedIndex()==8){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongKePNTheoThang8.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongKePNTheoThang8.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
        if(cboThang.getSelectedIndex()==9){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongkePntheoThang9.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongkePntheoThang9.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
        if(cboThang.getSelectedIndex()==10){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongKePNtheoThang.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongKePNtheoThang.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
        if(cboThang.getSelectedIndex()==11){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongKePhieuNhapTheoThang.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongKePhieuNhapTheoThang.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
        if(cboThang.getSelectedIndex()==12){
        try{
        //"Documents\NetBeansProjects\DemoOnThi\src"
        String path = ".\\src\\ThongKePNTheoThang12.jrxml";
        JasperReport jasperReport = JasperCompileManager.compileReport(path);
        JasperPrint print = JasperFillManager.fillReport(jasperReport, param,con);
        //JasperPrint print = JasperFillManager.fillReport(path, param, con);
        JasperViewer.viewReport(print, false);
        }catch(Exception e){
            try {
                String path = ".\\src\\ThongKePNTheoThang12.jrxml";
                JasperReport jasperReport = JasperCompileManager.compileReport(path);
                JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
                //JasperPrint print = JasperFillManager.fillReport(path, param, con);
                JasperViewer.viewReport(print, false);
            } catch (JRException ex) {
               ex.printStackTrace();
            }
        }
        }
}//GEN-LAST:event_jButton3ActionPerformed

private void btnThongKeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThongKeActionPerformed
 // TODO add your handling code here:
    /*if (cboThang.getSelectedIndex() == 0) {
        this.searchThang1();
    }
    if (cboThang.getSelectedIndex() == 1) {
        this.searchThang2();
    }*/
    if (cboThang.getSelectedIndex() == 1) {
        this.searchThang1();
    }
     if (cboThang.getSelectedIndex() == 2) {
        this.searchThang2();
    }
    if (cboThang.getSelectedIndex() == 3) {
        this.searchThang3();
    }
    if (cboThang.getSelectedIndex() == 4) {
        this.searchThang4();
    }
    if (cboThang.getSelectedIndex() == 5) {
        this.searchThang5();
    }
    if (cboThang.getSelectedIndex() == 6) {
        this.searchThang6();
    }
    if (cboThang.getSelectedIndex() == 7) {
        this.searchThang7();
    }
    if (cboThang.getSelectedIndex() == 8) {
        this.searchThang8();
    }
    if (cboThang.getSelectedIndex() == 9) {
        this.searchThang9();
    }
    if (cboThang.getSelectedIndex() == 10) {
        this.searchThang10();
    }
    if (cboThang.getSelectedIndex() == 11) {
        this.searchThang11();
    }
    if (cboThang.getSelectedIndex() == 12) {
        this.searchThang12();
    }
}//GEN-LAST:event_btnThongKeActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnThongKe;
    private javax.swing.JComboBox cboThang;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblPhieuNhap;
    // End of variables declaration//GEN-END:variables
}
